/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.view.deposit;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.event.SelectEvent;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;
import src.domain.deposit.Bilyet;
import src.services.CRUEDService;

/**
 *
 * @author jasuke
 */
@ManagedBean
@SessionScoped
public final class SearchDepositBean implements Serializable{

    /**
     * Creates a new instance of SearchCustomer
     */
    
    private LazyDataModel<Bilyet> lazyModel;  
    private Bilyet selectedData;  
    private String cif, nama, norek;
        
    public SearchDepositBean() {
        selectedData = null;
        cif = null;
        nama = null;
        norek = null;
       // LoadData();
    }

    public Bilyet getSelectedData() {
        return selectedData;
    }

    public void setSelectedData(Bilyet selectedData) {
        this.selectedData = selectedData;
    }

    public String getCif() {
        return cif;
    }

    public void setCif(String cif) {
        this.cif = cif;
    }

    public String getNama() {
        return nama;
    }

    public void setNama(String nama) {
        this.nama = nama;
    }

    public String getNorek() {
        return norek;
    }

    public void setNorek(String norek) {
        this.norek = norek;
    }
        
    public void loadData() {
        lazyModel = new LazyDataModel<Bilyet>() {

            @Override
            public List<Bilyet> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) { 
                                                
                int start = first;
                int end = first + pageSize;

                filters.put("customer.cif", cif);
                filters.put("customer.customerName", nama);
                //filters.put("closeDate", "null");
                //filters.put("closedBy", "null");
                //filters.put("approvalUid", "notnull");

                List<Bilyet> list = (List) new CRUEDService().loadLazy("Bilyet", start, end, sortField, sortOrder, filters);
                
                Integer count = new CRUEDService().countLazy("Bilyet", filters);
                lazyModel.setRowCount(count);

                return list;
            }

        };
        
    }
                        
    public void onRowSelected(SelectEvent selectEvent) {
    }
    
    public LazyDataModel<Bilyet> getLazyModel () {
        return lazyModel;
    }
    
   
}
